# Maintainer: umarcor <unai.martinezcorral@ehu.eus>

_realname=iverilog
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=11.0.r8956.gf705e7b6
pkgrel=2
epoch=1
pkgdesc="Icarus Verilog, is a Verilog simulation and synthesis tool (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="http://iverilog.icarus.com/"
license=('GPLv2+')
groups=("${MINGW_PACKAGE_PREFIX}-eda")
depends=(
  "${MINGW_PACKAGE_PREFIX}-bzip2"
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-readline"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "autoconf"
  "man-db"
  "${MINGW_PACKAGE_PREFIX}-ghostscript"
  'git'
)

# NOTE: MSYS2 support was improved/fixed in 'master' (2020/12/04).
# When 12.0 is tagged/released, this should be changed to use a tarball instead.
_commit="f705e7b6"
source=("${_realname}::git+https://github.com/steveicarus/iverilog.git#commit=${_commit}")
sha256sums=('SKIP')

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "11.0.r%s.g%s" "$(git rev-list --count ${_commit})" "$(git rev-parse --short=8 ${_commit})"
}

prepare() {
  cd "${srcdir}/${_realname}"
  sh autoconf.sh
}

build() {
  cd "${srcdir}/${_realname}"

  CXXFLAGS+=" -std=gnu++14"

  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}

  make
}

check() {
  cd "${srcdir}/${_realname}"
  make check
#  git clone https://github.com/steveicarus/ivtest.git
#  cd ivtest
#  ./regress
}

package() {
  cd "${srcdir}/${_realname}"
  make DESTDIR="${pkgdir}" install
  mkdir -p "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}"
  mv "${pkgdir}${MINGW_PREFIX}"/*.pdf "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}"

  _licenses="${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
  mkdir -p "${_licenses}"
  install -m 644 COPYING "${_licenses}"
}
